package view.Accueil;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;

import view.Fenetre;
import view.Param;

@SuppressWarnings("serial")
public class RightPanel extends JPanel implements ActionListener {

	private JButton bQuit;
	private LogPanel pLog;

	public RightPanel() {

		// Agencement des conteneurs
		GridBagConstraints constraint = new GridBagConstraints();
		this.setLayout(new GridBagLayout());

		// Creation des conteneurs
		pLog = new LogPanel();
		InsPanel pIns = new InsPanel();
		bQuit = new JButton("Quitter le programme");

		// Ajout de la transparence
		this.setOpaque(false);


		// CONTRAINTE DU PANNEAU DE CONNEXION

		constraint.gridx = 1;
		constraint.gridy = 0;

		constraint.weightx = 0.5;
		constraint.weighty = 0.1;

		constraint.gridwidth = 10;
		constraint.gridheight = 10;

		constraint.fill = GridBagConstraints.BOTH;

		this.add(pLog, constraint);


		// CONTRAINTE DU PANNEAU D'INSCRIPTION

		constraint.gridy = 11;

		constraint.weighty = 0.8;

		constraint.gridheight = 80;

		this.add(pIns, constraint);


		// CONTRAINTE DU BOUTON "QUITTER LE PROGRAMME"

		constraint.gridy = 91;

		constraint.weighty = 0.1;

		constraint.gridheight = 10;

		constraint.fill = GridBagConstraints.CENTER;

		this.add(bQuit, constraint);

		// FIN DES CONTRAINTES


		// Ajout des marges
		this.setBorder(Param.wideMargin);

		// Ajout des ecouteurs aux boutons
		bQuit.addActionListener(this);

	}

	/**Renvoie le panneau de connexion (pour le focus automatique).**/
	public LogPanel getLog() {
		return pLog;
	}

	@Override
	public void actionPerformed(ActionEvent event) {

		if (event.getSource() == bQuit) {

			Fenetre.fen.erase();
			System.exit(0);

		}

	}
}
